package com.txy.webmanagement.control;

import com.gitee.sunchenbin.mybatis.actable.manager.common.BaseMysqlCRUDManager;
import com.txy.webmanagement.dto.SysMenuDTO;
import com.txy.webmanagement.model.SysMenu;
import com.txy.webmanagement.model.SysUser;
import com.txy.webmanagement.service.SysMenuService;
import com.txy.webmanagement.utils.RequestDataUtils;
import com.txy.webmanagement.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 目录管理
 */
@Controller
@RequestMapping(value = "menu")
public class SysMenuControl {
    @Autowired
    private SysMenuService sysMenuService;
    @RequestMapping(value = "index")
    public String index(SysMenuDTO dto, Model m) {
        List<SysMenu> list = sysMenuService.findPageList(dto);
        m.addAttribute("menuList", list);
        return "menu/index";
    }

    @RequestMapping(value = "gotoAdd")
    public String gotoAdd(SysMenuDTO dto, Model m) {
        SysUser user = UserUtils.getLoginUser();
        List<SysMenu> list = sysMenuService.findFirstMenuList(user.getTypeId());
        m.addAttribute("menuList", list);
        return "menu/add";
    }

    @RequestMapping(value = "add")
    @ResponseBody
    public RequestDataUtils add( SysMenuDTO dto) {
        RequestDataUtils req = sysMenuService.save(dto);
        return req;
    }

}
